{extend name="public/base"}

{block name="x-body"}
<style>
    .layui-form .layui-input-inline {
        width: 320px;
    }

    .layui-form .layui-form-label {
        width: 120px;
    }

    .send {
        display: {if !$res.type}none{/if};
    }
</style>
    <div class="x-body">
        <form class="layui-form">
            {if $id}
            <input type="hidden" name="id" value="{$id}">
            {/if}
          <div class="layui-form-item">
              <label for="name" class="layui-form-label">
                  优惠券名称
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="name" name="name" required="" lay-verify="required"
                  autocomplete="off" value="{$res.name}" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>
              </div>
          </div>

            <div class="layui-form-item">
                <label for="money" class="layui-form-label">
                    优惠券金额
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="money" name="money" required="" lay-verify="required"
                           autocomplete="off" value="{$res.money}" class="layui-input" onfocus="isPrice(this)">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>优惠券可抵扣金额
                </div>
            </div>

            <div class="layui-form-item">
                <label for="condition" class="layui-form-label">
                    消费金额
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="condition" name="condition" required="" lay-verify="required"
                           autocomplete="off" value="{$res.condition}" class="layui-input" onfocus="isPrice(this)">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                    订单需满足的最低消费金额(必需为整数)才能使用
                </div>
            </div>

            <div class="layui-form-item">
                <label for="createnum" class="layui-form-label">
                    发放数量
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="createnum" name="createnum" required="" lay-verify="required"
                           autocomplete="off" value="{$res.createnum}" class="layui-input" onfocus="isNum(this)">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                    发放数量限制(默认为0则无限制)
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">发放类型</label>
                <div class="layui-input-block">
                    <input type="radio" name="type" value="0" lay-filter="type" title="下单赠送" {$res.type == 0 ? 'checked' : ''}>
                    <input type="radio" name="type" value="1" lay-filter="type" title="指定时间发放" {$res.type == 1 ? 'checked' : ''}>
                    <input type="radio" name="type" value="2" lay-filter="type" title="免费领取" {$res.type == 2 ? 'checked' : ''}>
                </div>
            </div>

            <div class="layui-form-item send">
                <label class="layui-form-label">
                    发放起始日期
                </label>
                <div class="layui-input-inline">
                    <input class="layui-input" placeholder="发放起始日期" name="send_start_time" autocomplete="off" id="start" value="{$res.send_start_time}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-item send">
                <label class="layui-form-label">
                    发放结束日期
                </label>
                <div class="layui-input-inline">
                    <input class="layui-input" placeholder="发放结束日期" name="send_end_time" autocomplete="off" id="end" value="{$res.send_end_time}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    使用起始日期
                </label>
                <div class="layui-input-inline">
                    <input class="layui-input" placeholder="使用起始日期" name="use_start_time" autocomplete="off" id="start" value="{$res.use_start_time}" required="" lay-verify="required">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    使用结束日期
                </label>
                <div class="layui-input-inline">
                    <input class="layui-input" placeholder="使用结束日期" name="use_end_time" autocomplete="off" id="start" value="{$res.use_end_time}" required="" lay-verify="required">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

          <div class="layui-form-item">
              <label class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">
                  {$id ? '修改' : '增加'}
              </button>
          </div>
      </form>
    </div>
    <script>
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
        
          form.on('radio(type)', function(data){
              if(data.value != 0){
                $('.send').css('display', 'block');
              }else{
                $('.send').css('display', 'none');
              }
          })
        });

        formData('{:url("promotion/coupon_form")}', 'add', function (){
            parent.location.reload();
            // 获得frame索引
            var index = parent.layer.getFrameIndex(window.name);
            //关闭当前frame
            parent.layer.close(index);
        }, false);
    </script>
{/block}